Compiler error: Variable or field declared void [closed]

Posted by ?? ? on Stack Overflow See other posts from Stack Overflow or by ?? ?
Published on 2011-11-26T09:44:07Z Indexed on 2011/11/26 9:52 UTC
Read the original article Hit count: 247

Filed under:

i get some error when i try to run this, could someone please tell me the mistakes, thank you!

[error: C:\Users\Ethan\Desktop\Untitled1.cpp In function `int main()':

25 C:\Users\Ethan\Desktop\Untitled1.cpp variable or field `findfactors' declared void

25 C:\Users\Ethan\Desktop\Untitled1.cpp initializer expression list treated as compound expression]

#include<iostream>
#include<cmath>
using namespace std;

void prompt(int&, int&, int&);
int gcd(int , int , int );//3 input, 3 output
void findfactors(int , int , int, int, int&, int&);//3 input, 2 output
void display(int, int, int, int, int);//5 inputs

int main()
{
int a, b, c; //The coefficients of the quadratic polynomial
int ag, bg, cg;//value of a, b, c after factor out gcd
int f1, f2; //The two factors of a*c which add to be b
int g; //The gcd of a, b, c

prompt(a, b, c);//Call the prompt function

g=gcd(a, b, c);//Calculation of g

void findfactors(a, b, c, f1, f2);//Call findFactors on factored polynomial

display(g, f1, f2, a, c);//Call display function to display the factored polynomial

system("PAUSE");
return 0;
}

void prompt(int& num1, int& num2, int& num3) //gets 3 ints from the user
{
    cout << "This program factors polynomials of the form ax^2+bx+c."<<endl;
    while(num1==0)
    {
        cout << "Enter a value for a: ";
        cin >> num1;
        if(num1==0)
        {
            cout<< "a must be non-zero."<<endl;
        }
    }

    while(num2==0 && num3==0)
    {
        cout << "Enter a value for b: ";
        cin >> num2;
        cout << "Enter a value for c: ";
        cin >> num3;
        if(num2==0 && num3==0)
        {
            cout<< "b and c cannot both be 0."<<endl;
        }
    }
}

int gcd(int num1, int num2, int num3)
{
int k=2, gcd=1;
while (k<=num1 && k<=num2 && k<=num3)
{
    if (num1%k==0 && num2%k==0 && num3%k==0)
        gcd=k;
    k++;
}

return gcd;
}

void findFactors(int Ag, int Bg, int Cg,int& F1, int& F2)
{
int y=Ag*Cg;
int z=sqrt(abs(y));

for(int i=-z; i<=z; i++) //from -sqrt(|y|) to sqrt(|y|)
{
    if(i==0)i++; //skips 0

    if(y%i==0) //if i is a factor of y
    {
        if(i+y/i==Bg) //if i and its partner add to be b
            F1=i, F2=y/i;
        else
            F1=0, F2=0;
    }
}
}

void display(int G, int factor1, int factor2, int A, int C)
{
int k=2, gcd1=1;
while (k<=A && k<=factor1)
{
    if (A%k==0 && factor1%k==0)
        gcd1=k;
    k++;
}

int t=2, gcd2=1;
while (t<=factor2 && t<=C)
{
    if (C%t==0 && factor2%t==0)
        gcd2=t;
    t++;
}
cout<<showpos<<G<<"*("<<gcd1<<"x"<<gcd2<<")("<<A/gcd1<<"x"<<C/gcd2<<")"<<endl;
}

© Stack Overflow or respective owner

Related posts about c++